#include "wxstimer.h"
#include "../wxsitemresdata.h"
#include <wx/timer.h>

namespace {
  wxsRegisterItem<wxsTimer> Reg( _T( "Timer" ), _T( "Timer" ), wxsTTool, _T( "工具" ), 20, false );
  WXS_EV_BEGIN( wxsTimerEvents )
  WXS_EVI( EVT_TIMER, wxEVT_TIMER, wxTimerEvent, Trigger )
  WXS_EV_END()

}
wxsTimer::wxsTimer( wxsItemResData* Data ):
  wxsTool( Data, &Reg.Info, wxsTimerEvents, 0, flVariable | flId | flSubclass | flExtraCode ) {
  m_Interval = 0;
  m_OneShot = false;
}

void wxsTimer::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
  case wxsCPP: {
    AddHeader( _T( "<wx/timer.h>" ), GetInfo().ClassName, hfInPCH );
    Codef( _T( "%ASetOwner(this, %I);\n" ) );
    if( m_Interval > 0 ) {
      Codef( _T( "%AStart(%d, %b);\n" ), m_Interval, m_OneShot );
    }
    BuildSetupWindowCode();
    return;
  }
  case wxsUnknownLanguage:
  default: {
    wxsCodeMarks::Unknown( _T( "wxsTimer::OnBuildCreatingCode" ), GetLanguage() );
  }
  }
}

void wxsTimer::OnEnumToolProperties( M_Code_unused long Flags ) {
  WXS_LONG( wxsTimer, m_Interval, _T( "Interval" ), _T( "interval" ), 0 );
  WXS_BOOL( wxsTimer, m_OneShot, _T( "One Shot" ), _T( "oneshot" ), false );
}
